<template>
  <Form
    :label-width="100"
    ref="formValidate"
    :rules="ruleValidate"
    :model="formValidate"
  >
    <FormItem label="开始时间" prop="startDateTemp">
      <DatePicker type="date" v-model="formValidate.startDateTemp" placeholder="开始时间" transfer
                  format="yyyy-MM-dd"></DatePicker>
    </FormItem>
    <FormItem label="结束时间" prop="startDateTemp">
      <DatePicker type="date" v-model="formValidate.endDateTemp" placeholder="开始时间" transfer
                  format="yyyy-MM-dd"></DatePicker>
    </FormItem>

    <FormItem>
      <Button
        type="primary"
        @click="handleSubmit('formValidate')"
      >确定
      </Button>
      <Button @click="publicReset('formValidate')" style="margin-left: 8px">取消</Button>
    </FormItem>
  </Form>
</template>

<script>
import { updateMixin } from '../../../mixin'
import { formatYYYYMMDD } from '../../../utils/date'
import { backupFile } from '../../../api/modules/system-log/backupFile'
import message from '../../../utils/message'

export default {
  name: 'Update',
  mixins: [updateMixin],
  data () {
    return {
      // 表单数据
      formValidate: {
        startDate: '',
        endDate: '',
        startDateTemp: '',
        endDateTemp: ''
      },
      // 表单校验规则
      ruleValidate: {
        startDateTemp: [{ required: true, message: '当前项不能为空', trigger: 'blur', type: 'date' }]
      }
    }
  },
  mounted () {

  },
  methods: {
    handleSubmit (name) {
      this.$refs[name].validate((valid) => {
        // 校验通过
        if (valid) {
          this.formValidate.startDate = formatYYYYMMDD(this.formValidate.startDateTemp)
          this.formValidate.endDate = formatYYYYMMDD(this.formValidate.endDateTemp)
          backupFile(this.formValidate).then(data => {
            message.message.success(data.message)
            // 关闭对话框并重新请求数据
            this.$emit('closeView', 1)
          })
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
